<!DOCTYPE html>
<html>
<head>
{include file="public/meta"} 
<title>用户注册 - {$maccms.site_name}</title>
<meta name="keywords" content="{$maccms.site_keywords}"/>
<meta name="description" content="{$maccms.site_description}"/> 
{include file="public/include"}
</head>
<body>
{include file="public/head"}
<div id="conch-content" class="conch-content">
<div class="conch-ctwrap">
    <div class="container">
    <div class="hl-member">
    <div class="hl-reg-wrap">
        <form method="post" id="fm" action="">
			<h2 class="hl-reg-title">用户注册</h2>
			<div class="hl-reg-group">
				<label>账号</label><input type="text" id="user_name" name="user_name" class="hl-reg-control" placeholder="请输入您的登录账号">
			</div>
			<div class="hl-reg-group">
				<label>密码</label><input type="password" id="user_pwd" name="user_pwd" class="hl-reg-control" placeholder="请输入您的登录密码">
			</div>
			<div class="hl-reg-group">
				<label>确认密码</label><input type="password" id="user_pwd2" name="user_pwd2" class="hl-reg-control" placeholder="请输入您的确认密码">
			</div>
			{if condition="$user_config.reg_phone_sms neq 0"}
			<input type="hidden" name="ac" value="phone">
			<div class="hl-reg-group">
				<label>手机号</label><input type="text" class="hl-reg-control hl-reg-w2" id="to" name="to" placeholder="请输入手机号"><input type="button" class="hl-reg-w3 hl-reg-yzm hl-text-conch" id="btn_send_sms" value="获取验证码"/>
			</div>
			<div class="hl-reg-group">
				<label>验证码</label><input type="text" class="hl-reg-control" id="code" name="code" placeholder="请输入手机验证码">
			</div>
			{elseif condition="$user_config.reg_email_sms neq 0"}
			<input type="hidden" name="ac" value="email">
			<div class="hl-reg-group">
				<label>邮箱</label><input type="text" class="hl-reg-control hl-reg-w2" id="to" name="to" placeholder="请输入邮箱"><input type="button" class="hl-reg-w3 hl-reg-yzm hl-bg-subs" id="btn_send_sms" value="获取验证码"/>
			</div>
			<div class="hl-reg-group">
				<label>验证码</label><input type="text" class="hl-reg-control" id="code" name="code" placeholder="请输入邮箱验证码">
			</div>
			{/if}

			{if condition="$user_config.reg_verify neq 0"}
			<div class="hl-reg-group">
				<label>验证码</label><input type="text" class="hl-reg-control hl-reg-w2" id="verify" name="verify" placeholder="请输入验证码"><img class="hl-reg-w3" id="verify_img" src="{:url('verify/index')}" onClick="this.src=this.src+'?'"  alt="单击刷新" />
			</div>
			{/if}
			<input type="button" id="btn_submit" class="hl-btn-submit hl-bg-conch" value="立即注册">
		</form>
        <div class="hl-reg-go hl-text-center clearfix">
            <a href="{$maccms.path}">返回首页</a><a href="{:url('user/login')}">登录账号</a><a href="{:url('user/findpass')}">忘记密码</a>
        </div>
    </div>
    </div>
    </div>
</div>
</div>
{include file="public/foot"}
<script type="text/javascript">
    var countdown=60;
    function settime(val) {
        if (countdown == 0) {
            val.removeAttribute("disabled");
            val.value="获取验证码";
            countdown = 60;
            return true;
        } else {
            val.setAttribute("disabled", true);
            val.value="重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function() {settime(val) },1000)
    }
		$("body").bind('keyup',function(event) {
			if(event.keyCode==13){ $('#btnLogin').click(); }
		});

        $('#btn_send_sms').click(function(){
            var ac = $('input[name="ac"]').val();
            var to = $('input[name="to"]').val();
            if(ac=='email') {
                var pattern = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                var ex = pattern.test(to);
                if (!ex) {
                    alert('邮箱格式不正确');
                    return;
                }
            }
            else if(ac=='phone') {
                var pattern=/^[1][0-9]{10}$/;
                var ex = pattern.test(to);
                if (!ex) {
                    alert('手机号格式不正确');
                    return;
                }
            }
            else{
                alert('参数错误');
                return;
            }
            settime(this);
            var data = $("#fm").serialize();

            $.ajax({
                url: "{:url('user/reg_msg')}",
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    //开启loading
                },
                success: function (r) {
                    alert(r.msg);
                },
                complete: function () {
                    //结束loading
                }
            });
        });
		$('#btn_submit').click(function() {
			if ($('#user_name').val()  == '') { alert('请输入用户！'); $("#user_name").focus(); return false; }
			if ($('#user_pwd').val()  == '') { alert('请输入密码！'); $("#user_pwd").focus(); return false; }
			if ($('#verify').val()  == '') { alert('请输入验证码！'); $("#verify").focus(); return false; }

			$.ajax({
				url: "{:url('user/reg')}",
				type: "post",
				dataType: "json",
				data: $('#fm').serialize(),
				beforeSend: function () {
					$("#btn_submit").css("background","#fd6a6a").val("loading...");
				},
				success: function (r) {
					alert(r.msg);
					if(r.code==1){
						location.href="{:url('user/login')}";
					}
					else{
						$('#verify_img').click();
					}
				},
				complete: function () {
					$("#btn_submit").css("background","#fa4646").val("立即注册");
				}
			});
		});
</script>
</body>
</html>